
#include <util/delay.h>
#include <avr/io.h>

#define SER_PORT   PORTC
#define SER_DDR    DDRC

#define SER_CLOCK   (1<<1)
#define SER_PRESENT (1<<3)
#define SER_DATA    (1<<5)

void Shift74HC595_Write8(unsigned char v)
{
	SER_DDR  |= SER_CLOCK | SER_PRESENT | SER_DATA;

	for (char c=0;c<8;c++)
	{
		if ( (v&128)>0 )
			SER_PORT |= SER_DATA;
		else
			SER_PORT &= ~SER_DATA;

		SER_PORT |= SER_CLOCK;

		_delay_us(1);

        SER_PORT &= ~SER_CLOCK;
		SER_PORT &= ~SER_DATA;

		v<<=1;
	}


	SER_PORT |= SER_PRESENT;	
	_delay_us(1);
    SER_PORT &= ~SER_PRESENT;
}

void Shift74HC595_Write16(unsigned int v)
{
	SER_DDR  |= SER_CLOCK | SER_PRESENT | SER_DATA;

	for (char c=0;c<16;c++)
	{
		if ( (v&(1<<15)) >0 )
			SER_PORT |= SER_DATA;
		else
			SER_PORT &= ~SER_DATA;

		SER_PORT |= SER_CLOCK;

		_delay_us(1);

        SER_PORT &= ~SER_CLOCK;
		SER_PORT &= ~SER_DATA;

		v<<=1;
	}


	SER_PORT |= SER_PRESENT;	
	_delay_us(1);
    SER_PORT &= ~SER_PRESENT;
}
